package cc.catface.common.output;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.ToString;

@Data
@ToString
@NoArgsConstructor
@AllArgsConstructor
public class ResultBody {

    private String code;
    private String message;
    private Object data;

    public ResultBody(String code, String message) {
        this.code = code;
        this.message = message;
    }

    //成功
    public static ResultBody success(Object data) {
        return new ResultBody(ErrorCode.SUCCESS.getCode(), ErrorCode.SUCCESS.getMessage(), data);
    }

    public static ResultBody success() {
        return success(null);
    }

    //失败
    public static ResultBody error(String code, String message) {
        return new ResultBody(code, message, null);
    }

    //供GlobalExceptionHandler全局拦截异常返回
    public static ResultBody error(IBaseCode baseCode) {
        return new ResultBody(baseCode.getCode(), baseCode.getMessage(), null);
    }

    public static ResultBody error(String message) {
        return new ResultBody("-1", message, null);
    }

    public static ResultBody error(Object error) {
        return new ResultBody("-2", "error", error);
    }
}
